package com.renchunlin.camerademo;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Result extends AppCompatActivity {

    private ImageView mIv_Image;
    private String path;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result);

        initView();
    }

    private void initView() {
        Intent intent = getIntent();
        path = intent.getStringExtra("picPath");

        mIv_Image = findViewById(R.id.mIv_Image);

        /**
         * 对图片进行角度调整
         */
        try {
            FileInputStream fileInputStream = new FileInputStream(path);
            //将流对象转换为Bitmap
            Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream);
            //创建一个新的Bitmap 将角度进行调整

            /**
             * 参数 Matrix是一个矩阵 我们需要调整的矩阵
             */

            Matrix matrix = new Matrix();
            //设置角度
            matrix.setRotate(90);

            bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

            mIv_Image.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
